﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Str2SbCollection
{
    public partial class frmRetuen : Form
    {
        public frmRetuen()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            if (btn.Name == "btnClear")
                txtSb.Text = "sb.Clear();\n";
            else
                txtSb.Text = string.Empty;

            string todostr = "";
            foreach (var c in txtStr.Text)
            {
                if (c != '\n')
                {
                    todostr += c;
                }
                else
                {
                    string result = todostr.Trim();
                    if (result.Length > 1 && result[result.Length - 1] == '+')
                    {
                        result = result.Substring(0, result.Length - 2).Trim();
                    }
                    if (result.Length > 1 && result[result.Length - 1] == ';')
                    {
                        result = result.Substring(0, result.Length - 1).Trim();
                    }
                    if (result.Trim() == string.Empty || result == null)
                        continue;
                    txtSb.Text += "sb.Append(" + result + ");\n";
                    todostr = "";
                }
            }
            Clipboard.SetDataObject(txtSb.Text);
        }

        private void txtStr_Click(object sender, EventArgs e)
        {
            txtStr.SelectAll();
        }

        private void txtSb_Click(object sender, EventArgs e)
        {
            txtSb.SelectAll();
        }
    }
}
